package jsonview.componet;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URI;
import java.net.URL;
import javax.swing.*;

/**
 * Copyright (C) 2017, Xiaomi Inc. All rights reserved.
 * Created by wen @ 17-6-24.
 * in jsonviewer
 */
public class LinkLabel extends JLabel implements MouseListener {
    private String ustr;

    public LinkLabel(String ustr, String text) {
        this.ustr = ustr;
        this.setText("<html><u>" + text + "</u></html>");
        this.setForeground(Color.BLACK);//设置链接颜色
        this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));//设置鼠标样式
        this.setToolTipText(text);//设置提示文字
        this.addMouseListener(this);
    }

    //点击时打开默认浏览器浏览指定的页面。
    public void mouseClicked(MouseEvent e) {
        try {
            Desktop.getDesktop().browse(new URI(ustr));
        } catch (Exception e1) {
            e.paramString();
        }
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
    }
}
